package com.qiangesoft.blog.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 接口文档配置
 *
 * @author qiange
 * @date 2023-06-01
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
public class Knife4jConfig {

    @Bean
    public Docket webRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("博客前台")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qiangesoft.blog.controller.web"))
                .paths(PathSelectors.any())
                .build();

    }

    @Bean
    public Docket manageRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("管理后台")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qiangesoft.blog.controller.manage"))
                .paths(PathSelectors.any())
                .build();

    }

    /**
     * 详细信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("博客接口文档")
                .description("文档用于前后端接口联调，方便开发")
                .termsOfServiceUrl("http://localhost:8080/")
                .contact(new Contact("qiange", "https://www.qiangesoft.cn", "1111@qq.com"))
                .version("v1.0.0")
                .build();
    }
}
